#include "simple_sprintf.h"
#include "math/large_int.h"
#include "math/bitOperation.h"
#include "stdio.h"
#include "stdbool.h"

void main(void)
{
	fprintf(stdout, "-------begin--------\r\n");

	mPrintf("123 %u %i %s \r\n", 123, -556677, "abc");

	sLargeInt_t a;
	sLargeInt_t b;
	sLargeInt_t c;
	// positive
	fprintf(stdout, "-----positive\r\n");
	largeIntParse(&a, "1234567");
	largeIntParse(&b, "1234566");
	
	largeIntPrint(&a);
	largeIntPrint(&b);
	
	bool loe = largeIntIsLargerOrEqual(&a, &b);
	fprintf(stdout, "largeIntIsLargerOrEqual=%d\r\n", loe);
	
	largeIntAdd(&a, &b, &c);
	fprintf(stdout, "add\r\n");
	largeIntPrint(&c);
	
	largeIntSub(&a, &b, &c);
	fprintf(stdout, "sub\r\n");
	largeIntPrint(&c);

	// minus one
	fprintf(stdout, "-----minus first\r\n");
	largeIntParse(&a, "-1234567");
	largeIntParse(&b, "1234566");
	
	largeIntPrint(&a);
	largeIntPrint(&b);
	
	loe = largeIntIsLargerOrEqual(&a, &b);
	fprintf(stdout, "largeIntIsLargerOrEqual=%d\r\n", loe);
	
	largeIntAdd(&a, &b, &c);
	fprintf(stdout, "add\r\n");
	largeIntPrint(&c);
	
	largeIntSub(&a, &b, &c);
	fprintf(stdout, "sub\r\n");
	largeIntPrint(&c);

	largeIntMul(&a, &b, &c);
	fprintf(stdout, "mul\r\n");
	largeIntPrint(&c);

	// minus one
	fprintf(stdout, "-----minus second\r\n");
	largeIntParse(&a, "1234567");
	largeIntParse(&b, "-1234566");
	
	largeIntPrint(&a);
	largeIntPrint(&b);
	
	loe = largeIntIsLargerOrEqual(&a, &b);
	fprintf(stdout, "largeIntIsLargerOrEqual=%d\r\n", loe);
	
	largeIntAdd(&a, &b, &c);
	fprintf(stdout, "add\r\n");
	largeIntPrint(&c);
	
	largeIntSub(&a, &b, &c);
	fprintf(stdout, "sub\r\n");
	largeIntPrint(&c);

	largeIntMul(&a, &b, &c);
	fprintf(stdout, "mul\r\n");
	largeIntPrint(&c);

	// minus two
	fprintf(stdout, "-----minus both\r\n");
	largeIntParse(&a, "-1234567");
	largeIntParse(&b, "-1234566");
	
	largeIntPrint(&a);
	largeIntPrint(&b);
	
	loe = largeIntIsLargerOrEqual(&a, &b);
	fprintf(stdout, "largeIntIsLargerOrEqual=%d\r\n", loe);
	
	largeIntAdd(&a, &b, &c);
	fprintf(stdout, "add\r\n");
	largeIntPrint(&c);
	
	largeIntSub(&a, &b, &c);
	fprintf(stdout, "sub\r\n");
	largeIntPrint(&c);

	largeIntMul(&a, &b, &c);
	fprintf(stdout, "mul\r\n");
	largeIntPrint(&c);

	fprintf(stdout, "bit sum 0f 0x54 = %d\r\n", bitSum(0x54));

	fprintf(stdout, "-------end--------\r\n");
}